/***************************************************************************
 *                                                                         *
 * Copyright (c) 2007 - 2009 Nuvoton Technology Corp. All rights reserved.*
 *                                                                         *
 ***************************************************************************/
 

#ifdef ECOS
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "drv_api.h"
#include "diag.h"
#include "wbio.h"
#include "NUC900_GE.h"
#include "NUC900_reg.h"
#else
#include <stdio.h>
#include "NUC900_GE.h"
#include "wbio.h"
#ifdef _NUC900_
#include "NUC900_reg.h"
#else
#include "reg702.h"
#endif
#endif

/*
** NOTE:
** 
*/

void stretch_bitblt(int srcx, int srcy, int destx, int desty, int width, int height, int hsfN, int hsfM, int vsfN, int vsfM, int updown)
{
	UINT32 cmd32, dest_start, src_start, dimension, pitch;  	
	UINT32 stretch_ctl;

#ifdef DEBUG 
	printf("stretch_blt_image()\n");
    printf("(%d,%d)=>(%d,%d)\n", srcx, srcy, destx, desty);
    printf("width=%d height=%d\n", width, height);    	
#endif

	outpw(REG_2D_GEXYSORG, (int)GFX_START_ADDR);   //smf
    outpw(REG_2D_GEXYDORG, (int)GFX_START_ADDR);  //smf

	pitch = GFX_WIDTH << 16 | GFX_WIDTH; // pitch in pixel
    outpw(REG_2D_GESDP, pitch);

	src_start = srcy << 16 | srcx;
 	outpw(REG_2D_GESSXYL, src_start);
  
 	dest_start = desty << 16 | destx;
 	outpw(REG_2D_GEDSXYL, dest_start);
	  
	dimension = height << 16 | width;
	outpw(REG_2D_GEDIXYL, dimension);  

	stretch_ctl = (vsfN << 24) | (vsfM << 16) | (hsfN << 8) | hsfM;
	outpw(REG_2D_TileXY_VHSF, stretch_ctl); 

	//if (filter==1)
	//{
		if (updown==1)
			cmd32 = 0xcc070000;
		else
			cmd32 = 0xcc030000; 
	//}
	/*
	else
	{
		if (updown==1)
			cmd32 = 0xcc0f0000;
			//cmd32 = 0xcc070000;  // smf
		else
			cmd32 = 0xcc0b0000;
			//cmd32 = 0xcc030000;    //smf
   	}
	*/
	outpw(REG_2D_GEC, cmd32); 

	outpw(REG_2D_GETG, 1); 
  
    while ((inpw(REG_2D_GEINTS)&0x01)==0); // wait for command complete  
  
    outpw(REG_2D_GEINTS, 1); // clear interrupt status 
}

/********************/
/* stretch_bitblt_specify function */
/* To stretch the specified area which is placed on other position */
/* attention : assign the width pitch of source */
/********************/
void stretch_bitblt_specify(int srcx, int srcy, int destx, int desty, int width, int height, int hsfN, int hsfM, int vsfN, int vsfM, int updown, int srcpitch)
{
	UINT32 cmd32, dest_start, src_start, dimension, pitch;  	
	UINT32 stretch_ctl;

#ifdef DEBUG 
	printf("stretch_blt_image()\n");
    printf("(%d,%d)=>(%d,%d)\n", srcx, srcy, destx, desty);
    printf("width=%d height=%d\n", width, height);    	
#endif

	pitch = GFX_WIDTH << 16 | srcpitch; // pitch in pixel
    outpw(REG_2D_GESDP, pitch);

	src_start = srcy << 16 | srcx;
 	outpw(REG_2D_GESSXYL, src_start);
  
 	dest_start = desty << 16 | destx;
 	outpw(REG_2D_GEDSXYL, dest_start);
	  
	dimension = height << 16 | width;
	outpw(REG_2D_GEDIXYL, dimension);  

	stretch_ctl = (vsfN << 24) | (vsfM << 16) | (hsfN << 8) | hsfM;
	outpw(REG_2D_TileXY_VHSF, stretch_ctl); 

	if (updown==1)
		cmd32 = 0xcc070000;
	else
		cmd32 = 0xcc030000; 
	

	outpw(REG_2D_GEC, cmd32); 

	outpw(REG_2D_GETG, 1); 
  
    while ((inpw(REG_2D_GEINTS)&0x01)==0); // wait for command complete  
  
    outpw(REG_2D_GEINTS, 1); // clear interrupt status  
}




